<?php
/// O'My Friends: Personal Social Network Graph on Facebook
/// author : Minkyu Shim (minkyu.shim@gmail.com
$facebook = new Facebook(array(
    'appId'  => FB_APP_ID,
    'secret' => FB_APP_SECRET
));

//if there is a facebook session in PHP $_SESSION
//if(isset($_SESSION['fb_session'])){
//    $facebook = $facebook->setSession($_SESSION['fb_session']);
//} 

//Still don't know whether the session is valid or not


$token = $facebook->getAccessToken();

//permissions
$perms = 'user_about_me,
friends_about_me,
user_notes,
user_status,
user_photos,
friends_notes,
friends_status,
friends_photos,
read_mailbox,
read_stream';

//Log in/out Buttons
if(strcmp($_SERVER['HTTP_HOST'],"localhost") == 0 || is_null($facebook->getSignedRequest())){
    $logout_button = "<a href='".$facebook->getLogoutUrl()."'><img id='logout_button' alt='logout' src='http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif'/></a>";
} else {
    $logout_button = null;
}
//$interstitial_page = 'http://'.$_SERVER['SERVER_NAME'].APP_DIR.'/login.php';
//error_log("$interstitial_page=".$interstitial_page);
$login_button = "<a href='".$facebook->getLoginUrl(array('scope' => $perms))."'><img id='login_button' alt='login' src='http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif'/></a>";
//$login_button = "<a href='".$facebook->getLoginUrl(array('redirect_uri' => $interstitial_page, 'scope' => $perms))."'><img id='login_button' alt='login' src='http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif'/></a>";
